<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 基于数组实现栈结构

        class Stack {
            item = []

            push(val) {
                this.item.push(val)
                return this.item
            }
            pop() {
                this.item.pop()
                return this.item
            }
            peek() {
                return this.item[this.item.length - 1]
            }
            isEmpty() {
                return this.item.length ? false : true
            }
            size() {
                return this.item.length
            }
            toString() {
                return this.item.join(' ')
            }
        }

        let s = new Stack()
        s.push(10)
        s.push(20)
        s.push(30)

        console.log(s)
        console.log(s.peek())
        console.log(s.toString())
        console.log(s.isEmpty())
        console.log(s.size())
        s.pop()
        console.log(s)
    </script>
</body>

</html>